package thread;

public class Demo24 {
    public static void main(String[] args) throws InterruptedException {
        Object object = new Object();
        System.out.println("等待之前");
        Object locker = new Object();
        Thread t = new Thread(() -> {
            System.out.println("解锁前");
            synchronized (object) {
                object.notify();
            }
            System.out.println("解锁后");
        });
        t.start();
        Thread.sleep(100); // 注意通知时间 不然就会错过 并且程序也不报错
        synchronized (object) { // locker 不行
            object.wait(1000); // 必须添加锁才行 因为执行之前默认会先解锁(object)
        }
        System.out.println("等待之后");
    }
}
